<?php
ob_start ();
define ( 'RELATIVE_PATH', '/web-admin' );
define ( 'APP_DIR', dirname ( __FILE__ ) );
define ( 'SITE_WEB_DISK_DIR', dirname ( constant ( 'APP_DIR' ) ) );
include_once (constant ( 'APP_DIR' ) . '/config/config.enviroment.php');
include_once (constant ( 'APP_DIR' ) . '/config/config.string.php');
include_once (constant ( 'PATH_INCLUDE' ) . '/class.db.php');
include_once (constant ( 'PATH_INCLUDE' ) . '/init_class_load.php');

class Application {
	public $error_message = '';
	function __construct() {
		$this->error_message = '';
	}
	private function permissionCheck() {
		$file_path = APP_DIR . RELATIVE_PATH . '/permission-check.php';
		if (file_exists ( $file_path )) {
			include ($file_path);
		}
	}
	private function action()
	{
		$last_slash_index =  strripos($_SERVER['PHP_SELF'], '/');
		$file_path = '';
		if ( $last_slash_index === FALSE ) {
			$file_path = APP_DIR . RELATIVE_PATH .'/'.$_SERVER['PHP_SELF'];
		}else{
			$file_path = APP_DIR . RELATIVE_PATH .'/'.substr($_SERVER['PHP_SELF'], $last_slash_index);
		}
		if (file_exists ( $file_path )) {
			include ($file_path);
		}
	}
	function run() {
		try{
			$this->permissionCheck ();
			$this->action ();
		}catch(Exception $ex){
			$this->error_message = $ex->getMessage();
		}
	}
}

$app = new Application ();
$app->run ();